home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2002 November / SGI IRIX Base Documentation 2002 November.iso / usr / share / catman / p_man / cat3c / getsubopt.z / getsubopt
Encoding:
Text File  |  2002-10-03  |  17.0 KB  |  198 lines

  1.  
  2.  
  3.  
  4. ggggeeeettttssssuuuubbbboooopppptttt((((3333CCCC))))                                                    ggggeeeettttssssuuuubbbboooopppptttt((((3333CCCC))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      _gggg_eeee_tttt_ssss_uuuu_bbbb_oooo_pppp_tttt - parse suboptions from a string
  10.  
  11. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.      _####_iiii_nnnn_cccc_llll_uuuu_dddd_eeee _<<<<_ssss_tttt_dddd_llll_iiii_bbbb_...._hhhh_>>>>
  13.      _iiii_nnnn_tttt _gggg_eeee_tttt_ssss_uuuu_bbbb_oooo_pppp_tttt _((((_cccc_hhhh_aaaa_rrrr _****_****_oooo_pppp_tttt_iiii_oooo_nnnn_pppp_,,,, _cccc_hhhh_aaaa_rrrr _****_cccc_oooo_nnnn_ssss_tttt _****_tttt_oooo_kkkk_eeee_nnnn_ssss_,,,, _cccc_hhhh_aaaa_rrrr _****_****_vvvv_aaaa_llll_uuuu_eeee_pppp_))))_;;;;
  14.  
  15. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  16.      _gggg_eeee_tttt_ssss_uuuu_bbbb_oooo_pppp_tttt parses suboptions in a flag argument that was initially parsed
  17.      by _gggg_eeee_tttt_oooo_pppp_tttt(3C).  These suboptions are separated by commas and may consist
  18.      of either a single token or a token-value pair separated by an equal
  19.      sign.  Since commas delimit suboptions in the option string, they are not
  20.      allowed to be part of the suboption or the value of a suboption.  A
  21.      command that uses this syntax is _mmmm_oooo_uuuu_nnnn_tttt(1M), which allows the user to
  22.      specify mount parameters with the _----_oooo option as follows:
  23.  
  24.       _mmmm_oooo_uuuu_nnnn_tttt _----_oooo _rrrr_wwww_,,,,_hhhh_aaaa_rrrr_dddd_,,,,_bbbb_gggg_,,,,_wwww_ssss_iiii_zzzz_eeee_====_1111_0000_2222_4444 _ssss_pppp_eeee_eeee_dddd_::::_////_uuuu_ssss_rrrr _////_uuuu_ssss_rrrr
  25.  
  26.      In this example there are four suboptions:  _rrrr_wwww, _hhhh_aaaa_rrrr_dddd, _bbbb_gggg, and _wwww_ssss_iiii_zzzz_eeee, the
  27.      last of which has an associated value of 1024.
  28.  
  29.      _gggg_eeee_tttt_ssss_uuuu_bbbb_oooo_pppp_tttt takes the address of a pointer to the option string, a vector
  30.      of possible tokens, and the address of a value string pointer.  It
  31.      returns the index of the token that matched the suboption in the input
  32.      string or -1 if there was no match.  If the option string at _o_p_t_i_o_n_p
  33.      contains only one suboption, _gggg_eeee_tttt_ssss_uuuu_bbbb_oooo_pppp_tttt updates _o_p_t_i_o_n_p to point to the
  34.      null character at the end of the string; otherwise it isolates the
  35.      suboption by replacing the comma separator with a null character, and
  36.      updates _o_p_t_i_o_n_p to point to the start of the next suboption.  If the
  37.      suboption has an associated value, _gggg_eeee_tttt_ssss_uuuu_bbbb_oooo_pppp_tttt updates _v_a_l_u_e_p to point to
  38.      the value's first character.  Otherwise it sets _v_a_l_u_e_p to _NNNN_UUUU_LLLL_LLLL.
  39.  
  40.      The token vector is organized as a series of pointers to null strings.
  41.      The end of the token vector is identified by a null pointer.
  42.  
  43.      When _gggg_eeee_tttt_ssss_uuuu_bbbb_oooo_pppp_tttt returns, if _v_a_l_u_e_p is not _NNNN_UUUU_LLLL_LLLL, then the suboption
  44.      processed included a value.  The calling program may use this information
  45.      to determine if the presence or lack of a value for this suboption is an
  46.      error.
  47.  
  48.      Additionally, when _gggg_eeee_tttt_ssss_uuuu_bbbb_oooo_pppp_tttt fails to match the suboption with the tokens
  49.      in the _t_o_k_e_n_s array, the calling program should decide if this is an
  50.      error, or if the unrecognized option should be passed to another program.
  51.  
  52. EEEEXXXXAAAAMMMMPPPPLLLLEEEE
  53.      The following code fragment shows how to process options to the _mmmm_oooo_uuuu_nnnn_tttt
  54.      command using _gggg_eeee_tttt_ssss_uuuu_bbbb_oooo_pppp_tttt.
  55.  
  56.      _####_iiii_nnnn_cccc_llll_uuuu_dddd_eeee _<<<<_ssss_tttt_dddd_llll_iiii_bbbb_...._hhhh_>>>>
  57.  
  58.      _cccc_hhhh_aaaa_rrrr _****_mmmm_yyyy_oooo_pppp_tttt_ssss_[[[[_]]]] _==== _{{{{
  59.      _####_dddd_eeee_ffff_iiii_nnnn_eeee _RRRR_EEEE_AAAA_DDDD_OOOO_NNNN_LLLL_YYYY        _0000
  60.  
  61.  
  62.                                                                         PPPPaaaaggggeeee 1111
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69. ggggeeeettttssssuuuubbbboooopppptttt((((3333CCCC))))                                                    ggggeeeettttssssuuuubbbboooopppptttt((((3333CCCC))))
  70.  
  71.  
  72.  
  73.                              _""""_rrrr_oooo_""""_,,,,
  74.      _####_dddd_eeee_ffff_iiii_nnnn_eeee _RRRR_EEEE_AAAA_DDDD_WWWW_RRRR_IIII_TTTT_EEEE       _1111
  75.                              _""""_rrrr_wwww_""""_,,,,
  76.      _####_dddd_eeee_ffff_iiii_nnnn_eeee _WWWW_RRRR_IIII_TTTT_EEEE_SSSS_IIII_ZZZZ_EEEE       _2222
  77.                              _""""_wwww_ssss_iiii_zzzz_eeee_""""_,,,,
  78.      _####_dddd_eeee_ffff_iiii_nnnn_eeee _RRRR_EEEE_AAAA_DDDD_SSSS_IIII_ZZZZ_EEEE        _3333
  79.                              _""""_rrrr_ssss_iiii_zzzz_eeee_""""_,,,,
  80.                              _NNNN_UUUU_LLLL_LLLL_}}}}_;;;;
  81.  
  82.      _mmmm_aaaa_iiii_nnnn_((((_aaaa_rrrr_gggg_cccc_,,,, _aaaa_rrrr_gggg_vvvv_))))
  83.              _iiii_nnnn_tttt  _aaaa_rrrr_gggg_cccc_;;;;
  84.              _cccc_hhhh_aaaa_rrrr _****_****_aaaa_rrrr_gggg_vvvv_;;;;
  85.      _{{{{
  86.              _iiii_nnnn_tttt _ssss_cccc_,,,, _cccc_,,,, _eeee_rrrr_rrrr_ffff_llll_aaaa_gggg_;;;;
  87.              _cccc_hhhh_aaaa_rrrr _****_oooo_pppp_tttt_iiii_oooo_nnnn_ssss_,,,, _****_vvvv_aaaa_llll_uuuu_eeee_;;;;
  88.              _eeee_xxxx_tttt_eeee_rrrr_nnnn _cccc_hhhh_aaaa_rrrr _****_oooo_pppp_tttt_aaaa_rrrr_gggg_;;;;
  89.              _eeee_xxxx_tttt_eeee_rrrr_nnnn _iiii_nnnn_tttt _oooo_pppp_tttt_iiii_nnnn_dddd_;;;;
  90.              _....
  91.              _....
  92.              _....
  93.              _wwww_hhhh_iiii_llll_eeee_((((_((((_cccc _==== _gggg_eeee_tttt_oooo_pppp_tttt_((((_aaaa_rrrr_gggg_cccc_,,,, _aaaa_rrrr_gggg_vvvv_,,,, _""""_aaaa_bbbb_ffff_::::_oooo_::::_""""_))))_)))) _!!!!_==== _----_1111_)))) _{{{{
  94.                      _ssss_wwww_iiii_tttt_cccc_hhhh _((((_cccc_)))) _{{{{
  95.                      _cccc_aaaa_ssss_eeee _''''_aaaa_''''_:::: _////_**** _pppp_rrrr_oooo_cccc_eeee_ssss_ssss _aaaa _oooo_pppp_tttt_iiii_oooo_nnnn _****_////
  96.                              _bbbb_rrrr_eeee_aaaa_kkkk_;;;;
  97.                      _cccc_aaaa_ssss_eeee _''''_bbbb_''''_:::: _////_**** _pppp_rrrr_oooo_cccc_eeee_ssss_ssss _bbbb _oooo_pppp_tttt_iiii_oooo_nnnn _****_////
  98.                              _bbbb_rrrr_eeee_aaaa_kkkk_;;;;
  99.                      _cccc_aaaa_ssss_eeee _''''_ffff_''''_::::
  100.                              _oooo_ffff_iiii_llll_eeee _==== _oooo_pppp_tttt_aaaa_rrrr_gggg_;;;;
  101.                              _bbbb_rrrr_eeee_aaaa_kkkk_;;;;
  102.                      _cccc_aaaa_ssss_eeee _''''_????_''''_::::
  103.                              _eeee_rrrr_rrrr_ffff_llll_aaaa_gggg_++++_++++_;;;;
  104.                              _bbbb_rrrr_eeee_aaaa_kkkk_;;;;
  105.                      _cccc_aaaa_ssss_eeee _''''_oooo_''''_::::
  106.                              _oooo_pppp_tttt_iiii_oooo_nnnn_ssss _==== _oooo_pppp_tttt_aaaa_rrrr_gggg_;;;;
  107.                              _wwww_hhhh_iiii_llll_eeee _((((_****_oooo_pppp_tttt_iiii_oooo_nnnn_ssss _!!!!_==== _''''_\\\\_0000_''''_)))) _{{{{
  108.                                      _ssss_wwww_iiii_tttt_cccc_hhhh_((((_gggg_eeee_tttt_ssss_uuuu_bbbb_oooo_pppp_tttt_((((_&&&&_oooo_pppp_tttt_iiii_oooo_nnnn_ssss_,,,,_mmmm_yyyy_oooo_pppp_tttt_ssss_,,,,_&&&&_vvvv_aaaa_llll_uuuu_eeee_)))) _{{{{
  109.                                      _cccc_aaaa_ssss_eeee _RRRR_EEEE_AAAA_DDDD_OOOO_NNNN_LLLL_YYYY _:::: _////_**** _pppp_rrrr_oooo_cccc_eeee_ssss_ssss _rrrr_oooo _oooo_pppp_tttt_iiii_oooo_nnnn _****_////
  110.                                              _bbbb_rrrr_eeee_aaaa_kkkk_;;;;
  111.                                      _cccc_aaaa_ssss_eeee _RRRR_EEEE_AAAA_DDDD_WWWW_RRRR_IIII_TTTT_EEEE _:::: _////_**** _pppp_rrrr_oooo_cccc_eeee_ssss_ssss _rrrr_wwww _oooo_pppp_tttt_iiii_oooo_nnnn _****_////
  112.                                              _bbbb_rrrr_eeee_aaaa_kkkk_;;;;
  113.                                      _cccc_aaaa_ssss_eeee _WWWW_RRRR_IIII_TTTT_EEEE_SSSS_IIII_ZZZZ_EEEE _:::: _////_**** _pppp_rrrr_oooo_cccc_eeee_ssss_ssss _wwww_ssss_iiii_zzzz_eeee _oooo_pppp_tttt_iiii_oooo_nnnn _****_////
  114.                                              _iiii_ffff _((((_vvvv_aaaa_llll_uuuu_eeee _====_==== _NNNN_UUUU_LLLL_LLLL_)))) _{{{{
  115.                                                      _eeee_rrrr_rrrr_oooo_rrrr______nnnn_oooo______aaaa_rrrr_gggg_((((_))))_;;;;
  116.                                                      _eeee_rrrr_rrrr_ffff_llll_aaaa_gggg_++++_++++_;;;;
  117.                                              _}}}} _eeee_llll_ssss_eeee
  118.                                                      _wwww_rrrr_iiii_tttt_eeee______ssss_iiii_zzzz_eeee _==== _aaaa_tttt_oooo_iiii_((((_vvvv_aaaa_llll_uuuu_eeee_))))_;;;;
  119.                                              _bbbb_rrrr_eeee_aaaa_kkkk_;;;;
  120.                                      _cccc_aaaa_ssss_eeee _RRRR_EEEE_AAAA_DDDD_SSSS_IIII_ZZZZ_EEEE _:::: _////_**** _pppp_rrrr_oooo_cccc_eeee_ssss_ssss _rrrr_ssss_iiii_zzzz_eeee _oooo_pppp_tttt_iiii_oooo_nnnn _****_////
  121.                                              _iiii_ffff _((((_vvvv_aaaa_llll_uuuu_eeee _====_==== _NNNN_UUUU_LLLL_LLLL_)))) _{{{{
  122.                                                      _eeee_rrrr_rrrr_oooo_rrrr______nnnn_oooo______aaaa_rrrr_gggg_((((_))))_;;;;
  123.                                                      _eeee_rrrr_rrrr_ffff_llll_aaaa_gggg_++++_++++_;;;;
  124.                                              _}}}} _eeee_llll_ssss_eeee
  125.  
  126.  
  127.  
  128.                                                                         PPPPaaaaggggeeee 2222
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135. ggggeeeettttssssuuuubbbboooopppptttt((((3333CCCC))))                                                    ggggeeeettttssssuuuubbbboooopppptttt((((3333CCCC))))
  136.  
  137.  
  138.  
  139.                                                      _rrrr_eeee_aaaa_dddd______ssss_iiii_zzzz_eeee _==== _aaaa_tttt_oooo_iiii_((((_vvvv_aaaa_llll_uuuu_eeee_))))_;;;;
  140.                                              _bbbb_rrrr_eeee_aaaa_kkkk_;;;;
  141.                                      _dddd_eeee_ffff_aaaa_uuuu_llll_tttt _::::
  142.                                              _////_**** _pppp_rrrr_oooo_cccc_eeee_ssss_ssss _uuuu_nnnn_kkkk_nnnn_oooo_wwww_nnnn _tttt_oooo_kkkk_eeee_nnnn _****_////
  143.                                              _eeee_rrrr_rrrr_oooo_rrrr______bbbb_aaaa_dddd______tttt_oooo_kkkk_eeee_nnnn_((((_vvvv_aaaa_llll_uuuu_eeee_))))_;;;;
  144.                                              _eeee_rrrr_rrrr_ffff_llll_aaaa_gggg_++++_++++_;;;;
  145.                                              _bbbb_rrrr_eeee_aaaa_kkkk_;;;;
  146.                                      _}}}}
  147.                              _}}}}
  148.                              _bbbb_rrrr_eeee_aaaa_kkkk_;;;;
  149.                      _}}}}
  150.              _}}}}
  151.              _iiii_ffff _((((_eeee_rrrr_rrrr_ffff_llll_aaaa_gggg_)))) _{{{{
  152.                      _////_**** _pppp_rrrr_iiii_nnnn_tttt _uuuu_ssss_aaaa_gggg_eeee _iiii_nnnn_ssss_tttt_rrrr_uuuu_cccc_tttt_iiii_oooo_nnnn_ssss _eeee_tttt_cccc_.... _****_////
  153.              _}}}}
  154.              _ffff_oooo_rrrr _((((_;;;; _oooo_pppp_tttt_iiii_nnnn_dddd_<<<<_aaaa_rrrr_gggg_cccc_;;;; _oooo_pppp_tttt_iiii_nnnn_dddd_++++_++++_)))) _{{{{
  155.                      _////_**** _pppp_rrrr_oooo_cccc_eeee_ssss_ssss _rrrr_eeee_mmmm_aaaa_iiii_nnnn_iiii_nnnn_gggg _aaaa_rrrr_gggg_uuuu_mmmm_eeee_nnnn_tttt_ssss _****_////
  156.              _}}}}
  157.              _....
  158.              _....
  159.              _....
  160.      _}}}}
  161.  
  162.  
  163. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  164.      getopt(3C)
  165.  
  166. DDDDIIIIAAAAGGGGNNNNOOOOSSSSTTTTIIIICCCCSSSS
  167.      _gggg_eeee_tttt_ssss_uuuu_bbbb_oooo_pppp_tttt returns -1 when the token it is scanning is not in the token
  168.      vector.  The variable addressed by _v_a_l_u_e_p contains a pointer to the first
  169.      character of the token that was not recognized rather than a pointer to a
  170.      value for that token.
  171.  
  172.      The variable addressed by _o_p_t_i_o_n_p points to the next option to be parsed,
  173.      or a null character if there are no more options.
  174.  
  175. NNNNOOOOTTTTEEEESSSS
  176.      During parsing, commas in the option input string are changed to null
  177.      characters.  White space in tokens or token-value pairs must be protected
  178.      from the shell by quotes.
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.                                                                         PPPPaaaaggggeeee 3333
  195.  
  196.  
  197.  
  198.